<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>模板html</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            background: rgba(90, 194, 255, 1);
        }

        .container {
            margin: 15px;
            padding: 0 10px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 4px 10px 0px rgba(0, 135, 214, 0.37);
            border-radius: 10px;
        }

        .row {
            position: relative;
            height: 50px;
        }

        .row::after {
            content: "";
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 1px;
            background-color: #D4D4D4;
            transform: scaleY(0.5);
        }

        .row:first-child::after {
            display: none;
        }

        .title {
            height: 18px;
            font-size: 15px;
            font-weight: 500;
            color: rgba(25, 25, 25, 1);
            line-height: 18px;
        }

        .value {
            font-size: 15px;
            font-weight: 400;
            color: rgba(90, 90, 90, 1);
        }

        .arrow {
            width: 17px;
            height: 17px;
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <div class="container" onclick="fnClearCache()">
            <div class="row" data-flex="main:justify cross:center">
                <div class="title">清除缓存</div>
                <div class="value">{{cache}}</div>
            </div>
        </div>

        <!-- <div class="container" onclick="fnDelAccount()">
            <div class="row" data-flex="main:justify cross:center">
                <div class="title">注销账号</div>
                <img src="../../image/ui/arrow_right_2.png" alt="" class="arrow">
            </div>
        </div> -->

        <div class="container">
            <div class="row" data-flex="main:justify cross:center" @click="openRichText('3','用户协议')">
                <div class="title">用户协议</div>
                <img src="../../image/ui/arrow_right_2.png" alt="" class="arrow">
            </div>
            <div class="row" data-flex="main:justify cross:center" @click="openRichText('4', '隐私协议')">
                <div class="title">隐私协议</div>
                <img src="../../image/ui/arrow_right_2.png" alt="" class="arrow">
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/saveFiles.js"></script>
<script type="text/javascript" src="../../script/localFile.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm;
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        fnInit();
        fnCache();
        initSaveFile();
        initLocalDownload();
    };

    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                cache: "0B"
            }
        });
    }

    function fnDelAccount() {
        var param = {
            alertConfirmFn: "delAccount()",
            alertType: "27"
        }
        fnOpenAlert(param);
    }

    function delAccount() {
        fnToast("申请成功，我们会在7天内处理您的注销申请！");
    }

    function fnClearCache() {
        if (vm.cache != "0B") {
            var param = {
                alertConfirmFn: "clearCache()",
                alertType: "18"
            }
            fnOpenAlert(param);
        } else {
            fnToast("暂无缓存");
        }
    }

    function clearCache() {
        api.clearCache(function () {
            clearFileById();
            clearDownload();
            api.setPrefs({
                key: 'download_course_id',
                value: ''
            });
            fnToast("清除成功");
            vm.cache = "0B";
        });
    }
    //获取缓存的大小
    function fnCache() {
        api.getCacheSize(function (ret) {
            var size = ret.size;
            if (size > 0) {
                vm.cache = fnBytesToSize(size);
            } else {
                vm.cache = "0B";
            }
        });
    }
    //计算缓存大小
    function fnBytesToSize(bytes) {
        if (bytes === 0) return '0B';
        var k = 1024;
        sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
        i = Math.floor(Math.log(bytes) / Math.log(k));
        return Math.floor((bytes / Math.pow(k, i))) + ' ' + sizes[i];
    }

    // 打开富文本页面
    function openRichText(param, title) {
        fnOpenPublicWin(title, 'question/richText_frm', {
            textType: param
        });
    }
</script>

</html>